//
//  HZJSingerListViewController.m
//  HZ_Beautiful_Music
//
//  Created by dllo on 16/4/6.
//  Copyright © 2016年 ui. All rights reserved.
//

#import "HZJSingerListViewController.h"
#import "HZJPlayListDetailViewController.h"
#import "HZJSingerMusicViewController.h"

#import "HSAFNetTool.h"
#import "HZJSingerListModel.h"
#import "HZJSingerLIstTVCell.h"
@interface HZJSingerListViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

#define URL @"&size=1000&page=1&app=ttpod&v=v8.1.4.2016011318&user_id=0&mid=iPhone8,1&f=f320&s=s310&imsi=&hid=&splus=9.0.2&active=1&net=2&openudid=00e5496604ba470f229b34929ee14d0eb192a8e8&idfa=2301BEB2-C95C-4AA8-A905-794EC5CED975&utdid=VrPuK0MAZLUDAGfmA9wxwiTF&alf=201200&bundle_id=com.ttpod.music&latitude=38.882548834006&longtitude=121.5391476381413"

@implementation HZJSingerListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self creatTableView];
    [self getData];
}

#pragma mark - tableview
- (void)creatTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    [_tableView registerClass:[HZJSingerLIstTVCell class] forCellReuseIdentifier:@"HZJSingerLIstTVCell"];
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HZJSingerLIstTVCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HZJSingerLIstTVCell"];
    cell.listModel = self.dataSource[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    HZJSingerListModel *singerListModel = self.dataSource[indexPath.row];
    HZJSingerMusicViewController *musicVC = [[HZJSingerMusicViewController alloc] init];
    musicVC.urlString = [NSString stringWithFormat:@"%@", singerListModel.singer_id];
    
    musicVC.picUrl = singerListModel.pic_url;
    
    [self.navigationController pushViewController:musicVC animated:YES];
    [_tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - 数据请求
- (void)getData {
    
    [HSAFNetTool GETNetWithUrl:[NSString stringWithFormat:@"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=%ld%@", (long)_singerModel.idNum.integerValue, URL] body:nil headerFile:nil response:HSJSON success:^(id result) {
        
        self.dataSource = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dic in result[@"data"]) {
            HZJSingerListModel *singerListModel = [[HZJSingerListModel alloc] initWithDataSource:dic];
            [self.dataSource addObject:singerListModel];
        }
        
        [_tableView reloadData];
    } failure:^(NSError *error) {
        NSLog(@"%@", error);
    }];
    
}



- (void)setIdStr:(NSString *)idStr {
    _idStr = idStr;
    [_tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
